import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int count = 0, ret = 0;
        String[] arr = new String[4];
        boolean flg = false;
        for (int i = 1; count < 2023; i++) {
            arr[0] = Integer.toString(i,2);
            arr[1] = Integer.toString(i,8);
            arr[2] = Integer.toString(i,10);
            arr[3] = Integer.toString(i,16);
            for (int j = 0; j < 4; j++) {
                if (i % bitSum(arr[j]) != 0) {
                    flg = true;
                    break;
                }
            }
            if (!flg) {
                count++;
                ret = i;
                flg = true;
            }
        }
        System.out.println(ret);
        scan.close();
    }

    public static int bitSum(String s) {
        int sum = 0;
        for (char c : s.toCharArray()) {
            sum += c - '0';
        }
        return sum;
    }
}
